package priv.tuyou.system.tag;

import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.commons.lang.math.NumberUtils;

import priv.tuyou.constants.WebContext;
import priv.tuyou.system.dao.ISystemMenuDao;
import priv.tuyou.system.po.SystemMenu;
import priv.tuyou.system.service.ISystemMenuService;
import priv.tuyou.tag.BaseTag;

/**
 * 系统菜单操作标签
 * @author：涂有
 * @date 2017年1月2日 下午11:17:10
 */
public class SystemMenuTag extends BaseTag{

	private static final long serialVersionUID = -7118316888626049926L;
	protected ISystemMenuDao systemMenuDao = WebContext.getBean(ISystemMenuDao.class);
	protected ISystemMenuService systemMenuService = WebContext.getBean(ISystemMenuService.class);

	@Override
	public int doStartTag() throws JspException {
		
		if("queryTop".equalsIgnoreCase(type)){//得到顶级菜单
			
			List<SystemMenu> list = systemMenuDao.getChildren(null); 
			pageContext.setAttribute(var, list);
		}else if("get".equalsIgnoreCase(type)){
			
			SystemMenu menu = dao.getIgnoreDeleted(SystemMenu.class, value);
			pageContext.setAttribute(var, menu);
		}else if("queryChildren".equalsIgnoreCase(type)){
			
			List<SystemMenu> list = systemMenuDao.getChildren(NumberUtils.toLong(value)); 
			pageContext.setAttribute(var, list);
		}else if("getPath".equalsIgnoreCase(type)){
			
			SystemMenu menu = dao.getIgnoreDeleted(SystemMenu.class, value);
			String path = systemMenuService.getPath(menu);
			pageContext.setAttribute(var, path);
		}
		return super.doStartTag();
	}
}
